import os
import logging
from logging.handlers import RotatingFileHandler

from dotenv import load_dotenv

load_dotenv()

log_path = os.getenv("LOG_PATH")

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

max_bytes = 1024*1024*100  # 设置日志文件大小为 10MB，可以根据需要调整大小
backup_count = 100  # 设置备份文件数量

# 创建一个 FileHandler，将日志输出到文件
file_handler = RotatingFileHandler(log_path, mode='a', maxBytes=max_bytes, backupCount=backup_count)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)

# 将 Handler 添加到 logger
logger.addHandler(file_handler)

